#!/bin/bash

######字体颜色设置#########
Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
Yello_font_prefix="\033[33m" && Blue_font_prefix="\033[34m" && Pink_font_prefix="\033[35m"
######字体颜色设置#########

echo -e "${Green_font_prefix}安装相关依赖...${Font_color_suffix}"
yum install -y yum-utils device-mapper-persistent-data lvm2

echo -e "${Green_font_prefix}安装docker...${Font_color_suffix}"
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache fast
sudo yum -y install docker-ce
if [ $? -eq 0 ]; then
	echo -e "${Green_font_prefix}docker安装成功!${Font_color_suffix}"
else
	echo -e "${Red_font_prefix}docker安装失败！！！！!${Font_color_suffix}"
fi

echo -e "${Green_font_prefix}替换为中国镜像地址...${Font_color_suffix}"
cp docker.service /lib/systemd/system/
echo -e "${Green_font_prefix}刷新配置...${Font_color_suffix}"
systemctl daemon-reload

echo -e "${Green_font_prefix}启动docker...${Font_color_suffix}"
systemctl start docker
if [ $? -eq 0 ]; then
	echo -e "${Green_font_prefix}docker启动成功!${Font_color_suffix}"
else
	echo -e "${Red_font_prefix}docker启动失败！！！！!${Font_color_suffix}"
fi

echo -e "${Green_font_prefix}安装Rancher面板...${Font_color_suffix}"
docker pull rancher/server
if [ $? -eq 0 ]; then
	echo -e "${Green_font_prefix}成功!${Font_color_suffix}"
else
	echo -e "${Red_font_prefix}失败！！！！!${Font_color_suffix}"
fi

echo -e "${Green_font_prefix}启动Rancher面板...${Font_color_suffix}"
docker run --name rancher-server -p 8000:8080 -v /etc/localtime:/etc/localtime:ro  -d  rancher/server
if [ $? -eq 0 ]; then
	echo -e "${Green_font_prefix}Rancher面板启动成功,端口8000!${Font_color_suffix}"
else
	echo -e "${Red_font_prefix}失败！！！！!${Font_color_suffix}"
fi
